package nina.yiyou.performance.s11collect.output

import nina.yiyou.salary.output.util.CsvLineMaker
import nina.yiyou.salary.output.util.OutCsvWriter

import java.nio.file.Path
import java.util.stream.Collectors

class CollectEmployeeCsvExporter {

  CollectEmployeeCsvExporter(List<Map> employeeList, List<String> keyList, Path csvPath) {
    _employeeList = employeeList
    _keyList = keyList
    _csvPath = csvPath
  }

  void export() {
    List lines = _employeeList.stream()
        .map { Map e -> _keyList.collect { e[it] } }
        .collect(Collectors.toList())

    new OutCsvWriter(_csvPath, ([_keyList] + lines).stream()
        .map { new CsvLineMaker(it as List).make() }
        .collect(Collectors.toList())).write()
  }

  private final List<Map> _employeeList
  private final List<String> _keyList

  private final Path _csvPath
}
